package com.daatak.mvc.finance;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.daatak.finance.business.CalculatorOptions;
import com.daatak.finance.business.FinancialBeanI;

//@Controller
public class CalculatorController {
	
	@Autowired
	FinancialBeanI financialBean;
	
	@InitBinder
	public void initBinder(WebDataBinder webDataBinder) {
	 SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
	 dateFormat.setLenient(false);
	 webDataBinder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
	 }
	
	

	@RequestMapping(value="/finance/calculator", method = RequestMethod.POST)
	public String showCalculationWidget(ModelMap model) {
		
		return "ajax.finance/financialCalculator";
	}
	
	@RequestMapping(value="/calculator/calculate", method = RequestMethod.POST)
	public @ResponseBody String calcuateFianancedAmount(@ModelAttribute CalculatorOptions financialPojo,ModelMap model) {
		model.addAttribute("financial", financialPojo);
		return "ajax.finance/rateCardBand";
	}


}
